from datetime import datetime

from exts import db


class User(db.Model):
    __tablename__ = 'user'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(20), nullable=False, unique=True)
    password = db.Column(db.String(256), nullable=False)
    phone = db.Column(db.String(11), nullable=False)
    email = db.Column(db.String(30)) # 邮箱
    icon = db.Column(db.String(100)) # 头像
    isdelete = db.Column(db.Boolean, default=False) # 逻辑上删除，不是物理上删除，比如注销了还保留一些信息
    rdatetime = db.Column(db.DateTime, default=datetime.now)
    
    # 增加一个字段和articles建立关系   backref='user'   back_populates
    articles = db.relationship('Articles', backref='user')

    def __repr__(self):
        return self.username

class UserInfo(db.Model):
    __tablename__ = 'userinfo'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    realname  = db.Column(db.String(20))
    gender = db.Column(db.Boolean, default=False)

    def __str__(self):
        return self.realname